package com.boot.dog.web.config.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.boot.dog.common.auth.DogUser;
import com.boot.dog.common.util.SecurityUtil;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @Author: MaxLv
 * @Date: 2019/12/2
 */
@Component
public class MetaHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        DogUser user = SecurityUtil.getUser();
        this.strictInsertFill(metaObject, "creator", String.class, user.getUsername());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        DogUser user = SecurityUtil.getUser();
        this.strictUpdateFill(metaObject, "modifier", String.class, user.getUsername());
        this.strictUpdateFill(metaObject, "modifyDate", LocalDateTime.class, LocalDateTime.now());
    }
}
